var thousandSeparator = function(n) {
    let count = 0
    let newStr = ''
    while(n){
        
        let cur = n % 10
        newStr += cur
        count += 1
        n = Math.floor(n/10)
        console.log(n)
        if(n){
            if(count%3 === 0){
                newStr += '.'
            }
        }
    }
    console.log(newStr)
};

thousandSeparator(987654321)